<?php
/**
 */


define("CACHE_PREFIX_LAJI_UID","_laji_uid");
class db_fanlaji_laji_uid extends db_base {
    
	var $table_name = "fanlaji_laji_uid";
	
	function db_fanlaji_laji_uid()
	{
		parent::db_base();
	}
	
	
	
	function get_laji_uid_list_order_by_jubao($uid="",$p=1,$pcount=20)
	{
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_LAJI_UID."-get_laji_uid_list_order_by_jubao-{$uid}-{$p}-{$pcount}";
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where_ary = array();;
			if(strlen($laji_have_del)>0)
			{
				$where_ary[] = "laji_have_del = {$laji_have_del}";
				
			}
			$where_ary[] = "status = 1";
			
			$where = join(" and ",$where_ary);
			$start = ($p-1)*$pcount;
			
			$sql =" select * from {$this->table_name} where laji_have_del = 0 and laji_uid not in (select laji_uid from fanlaji_jubao_uid where uid = {$uid}) order by jubao_count desc limit $start,$pcount";
			
			$content = $this->select($sql);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
		
	}
	
	
	/**
	 * 用户注册
	 * @param $user_name
	 * @param $password
	 */
	function insert_fanlaji_laji_uid($laji_uid,$laji_nickname)
	{
		// 插入数据
		$ary = array();

		$ary["laji_uid"] = $laji_uid;
		$ary["laji_nickname"] = $laji_nickname;
		$ary["user_status"] = 1;
		
		$ary["create_time"] = Date::get_date_time();
		$ary["status"] = 1;
		
		$ret = $this->insert($this->table_name, $ary);
		if ($ret)
		{
			/*$memcache = mem_cache::get_instance();
			$memcache->delete($key);*/
		}
		else
		{
			return false;
		}


		return $this->get_lastinsertid();
	}
	
	
	function update_fanlaji_laji_uid($laji_uid,$laji_have_del="",$jubao_count="")
	{
		// 插入数据
		$ary = array();

		if(strlen($jubao_count)>0)
		{
			$ary["jubao_count"] = $jubao_count;
			
		}
		if(strlen($laji_have_del)>0)
		{
			$ary["laji_have_del"] = $laji_have_del;
			
		}
		if($laji_have_del == 1)
		{
			$ary["del_time"] = Date::get_date_time();
		}
		
		
		
		$where = "laji_uid = {$laji_uid}";
		$ret = $this->update($this->table_name, $ary,$where);
		if ($ret)
		{
			/*$memcache = mem_cache::get_instance();
			$memcache->delete($key);*/
		}
		else
		{
			return false;
		}


		return $this->get_lastinsertid();
	}
	
	
###########################

	
	
	
	/**
	 * cron 获取food_tag
	 */
	function admin_get_count_by_search($status="")
	{
		$where= array();
		if(strlen($status) > 0)
		{
			$status = intval($status);
			$where[] = "status = {$status}";
		}
		
		
		$where= join(",",$where);
		
		$data = $this->get_listcount($this->table_name, $where);
		
		return $data;
	}
	
	
	/*
	 * cron获取topic_lisy
	 */
	function admin_get_list_by_search($status="",$p=1,$pcount=10)
	{
		$where= array();
		if(strlen($status) > 0)
		{
			$status = intval($status);
			$where[] = "status = {$status}";
		}
		
		$where= join(",",$where);
		
		$p = intval($p);
		$pcount = intval($pcount);
		
		
		$data = $this->get_alllist($this->table_name,$p,$pcount,"create_time desc",$where);
		
		return $data;
	}
	
	
	
	
	
	
	
	
	
	###############################
	
	
	/**
	 * cron 获取food_tag
	 */
	function cron_get_laji_uid_count($start_id)
	{
		
		$start_id = intval($start_id);
		
		$where=" id > $start_id  and laji_have_del =0 and status = 1 " ;
		
		$data = $this->get_listcount($this->table_name, $where);
		
		return $data;
	}
	
	
	/*
	 * cron获取topic_lisy
	 */
	function cron_get_laji_uid_list($start_id=0,$p=1,$pcount=10)
	{
		
		$start_id = intval($start_id);
		$p = intval($p);
		$pcount = intval($pcount);
		
		$start = ($p -1 ) * $pcount;
		$where=" id > $start_id  and laji_have_del =0 and status = 1 " ;
		
		$data = $this->get_alllist($this->table_name,$p,$pcount,"",$where);
		
		return $data;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}



